import i18n from '../../lang';
//会员过滤器

/**
 * 等级
 */
export function levelFilter(status) {
  if (!status) {
    return '';
  }
  let arrayList = JSON.parse(localStorage.getItem('levelKey'));
  let array = arrayList.filter((item) => status === item.id);
  if (array.length) {
    return array[0].name;
  } else {
    return '';
  }
}

/**
 * 标签
 */
export function tagFilter(status) {
  if (!status) {
    return '-';
  }
  let arr = JSON.parse(localStorage.getItem('tagAllList'));
  let obj = {};
  for (let i in arr) {
    obj[arr[i].id] = arr[i];
  }
  let strArr = status.split(',');
  let newArr = [];
  for (let item of strArr) {
    if (obj[item]) {
      newArr.push(obj[item].name);
    }
  }
  return newArr.join(',');
  // let array = arrayList.filter(item => status === item.id)
  // if(array.length){
  //   return array[0].name
  // }else{
  //   return ''
  // }
}

/**
 * 用户类型
 */
export function typeFilter(status) {
  const statusMap = {
    wechat: i18n.t('weiXinYongHu'),
    routine: i18n.t('xiaoChengXuYongHu'),
    h5: i18n.t('h5YongHu'),
  };
  return statusMap[status];
}

/**
 * 用户类型
 */
export function filterIsPromoter(status) {
  const statusMap = {
    true: i18n.t('tuiGuangYuan'),
    false: i18n.t('puTongYongHu'),
  };
  return statusMap[status];
}
